# Always include the include directory
include_directories(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/source /usr/include)

# Always include srcdir and builddir in include path
# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in
# about every subdir
# since cmake 2.4.0
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Put the include dirs which are in the source or build tree
# before all other include dirs, so the headers in the sources
# are prefered over the already installed ones
# since cmake 2.4.1
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
	
# Use colored output
# since cmake 2.4.0
set(CMAKE_COLOR_MAKEFILE ON)

# Put all built binaries and libraries into "bin"
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/library)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/library)

# Set default build type
#if(NOT CMAKE_BUILD_TYPE)
#    set(CMAKE_BUILD_TYPE Debug)
#endif(NOT CMAKE_BUILD_TYPE)

# Set compiler flags
set(COMMON_COMPILER_FLAGS
#	-fstrict-aliasing
#	-Weffc++
	-Wall
	-Wstrict-aliasing=2
	-Woverloaded-virtual
	-Wconversion
	-Wsign-compare
	-fno-rtti
	-ffast-math
)

set(RELEASE_COMPILER_FLAGS 
	-O2 
	-funroll-loops
	-fomit-frame-pointer 
	-fno-enforce-eh-specs 
	-fno-exceptions 
	-ftree-vectorize 
#	-ggdb0
)

set(TEST_COMPILER_FLAGS 
	-O2 
	-funroll-loops 
	-fexceptions 
	-ftree-vectorize 
	-ggdb2
)

set(DEBUG_COMPILER_FLAGS 
	-O0 
	-fexceptions
	-ggdb3
)

foreach(flag ${COMMON_COMPILER_FLAGS})
	add_definitions("${flag}")
endforeach(flag)

if(CMAKE_BUILD_TYPE MATCHES Debug)
	add_definitions(-DRS_DEBUG)
	foreach(flag ${DEBUG_COMPILER_FLAGS})
		add_definitions("${flag}")
	endforeach(flag)
elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
	add_definitions(-DRS_TEST)
	foreach(flag ${TEST_COMPILER_FLAGS})
		add_definitions("${flag}")
	endforeach(flag)
elseif(CMAKE_BUILD_TYPE MATCHES Release)
	add_definitions(-DRS_RELEASE)
	foreach(flag ${RELEASE_COMPILER_FLAGS})
		add_definitions("${flag}")
	endforeach(flag)
endif(CMAKE_BUILD_TYPE MATCHES Debug)